<?php

/**
 * Product form base class.
 *
 * @method Product getObject() Returns the current form's model object
 *
 * @package    tsantek-shop
 * @subpackage form
 * @author     Tomislav Šantek
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseProductForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'                     => new sfWidgetFormInputHidden(),
      'shop_id'                => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Shop'), 'add_empty' => false)),
      'discount_id'            => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Discount'), 'add_empty' => false)),
      'name'                   => new sfWidgetFormInputText(),
      'sku_code'               => new sfWidgetFormInputText(),
      'category_id'            => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Category'), 'add_empty' => false)),
      'description'            => new sfWidgetFormTextarea(),
      'price'                  => new sfWidgetFormInputText(),
      'price_action'           => new sfWidgetFormInputText(),
      'cached_fields'          => new sfWidgetFormInputText(),
      'is_featured'            => new sfWidgetFormInputCheckbox(),
      'is_available'           => new sfWidgetFormInputCheckbox(),
      'is_active'              => new sfWidgetFormInputCheckbox(),
      'is_inventory_trackable' => new sfWidgetFormInputCheckbox(),
      'show_global'            => new sfWidgetFormInputCheckbox(),
      'slug'                   => new sfWidgetFormInputText(),
      'created_at'             => new sfWidgetFormDateTime(),
      'updated_at'             => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'id'                     => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'shop_id'                => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Shop'))),
      'discount_id'            => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Discount'))),
      'name'                   => new sfValidatorString(array('max_length' => 255)),
      'sku_code'               => new sfValidatorString(array('max_length' => 32, 'required' => false)),
      'category_id'            => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Category'))),
      'description'            => new sfValidatorString(array('max_length' => 2000, 'required' => false)),
      'price'                  => new sfValidatorNumber(),
      'price_action'           => new sfValidatorNumber(array('required' => false)),
      'cached_fields'          => new sfValidatorPass(array('required' => false)),
      'is_featured'            => new sfValidatorBoolean(array('required' => false)),
      'is_available'           => new sfValidatorBoolean(array('required' => false)),
      'is_active'              => new sfValidatorBoolean(array('required' => false)),
      'is_inventory_trackable' => new sfValidatorBoolean(array('required' => false)),
      'show_global'            => new sfValidatorBoolean(array('required' => false)),
      'slug'                   => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'created_at'             => new sfValidatorDateTime(),
      'updated_at'             => new sfValidatorDateTime(),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorAnd(array(
        new sfValidatorDoctrineUnique(array('model' => 'Product', 'column' => array('slug'))),
        new sfValidatorDoctrineUnique(array('model' => 'Product', 'column' => array('slug'))),
      ))
    );

    $this->widgetSchema->setNameFormat('product[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'Product';
  }

}
